/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.geom.Dimension;

import com.bourre.data.collections.IndexedArray;

import fever.medias.video.VideoMetaData;

import fvaswing.components.reader.playlist.FvPlayListItem;
import fvaswing.components.reader.video.FvVideoMarker;

/**
 * Data structure for {@link fvaswing.components.reader.video.FvVideoList} tree node 
 * content
 * 
 * @author Romain Ecarnot
 */
class fvaswing.components.reader.video.FvVideoItem extends FvPlayListItem
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _phpStreaming : Boolean;
	private var _size : Dimension;	private var _duration : Number;	private var _meta : VideoMetaData;
	
	private var _markerList : IndexedArray;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function FvVideoItem( url : String, title : String, isPHP : Boolean )
	{
		super( url, title );
		
		_phpStreaming = ( isPHP != undefined ) ? isPHP : false;
		_markerList = new IndexedArray();
	}
	
	/**
	 * Sets bookmark for current video item.
	 * 
	 * <p>Markers list ( bookmark ) are defined throw xml playlist file.
	 * 
	 * <p>Example
	 * {@code
	 *   <root>
	 *   	<videos>
	 *   		<item>
	 *   			<url type="string">assets/video.flv</url>
	 *   			<title type="string">Introduction</title>
	 *   			<bookmark>
	 *   				<marker>
	 *   					<caption type="string">myCuePoint</caption>
	 *   					<time type="number">10.23</time>
	 *   				</marker>
	 *   			</bookmark>
	 *   		</item>
	 *   	</videos>
	 *   </root>
	 * }
	 */
	public function setBookmark( o : Object ) : Void
	{
		if( o.bookmark != "" )
		{
			var l : Number = o.marker.length;
			for( var i : Number = 0; i < l; i++ )
			{
				var x : Object = o.marker[i];
				_markerList.push( new FvVideoMarker( x.caption, x.time, x.preview ) );
			}
		}
	}
	
	/**
	 * Returns markers iterator.
	 */
	public function getBookmark() : Array
	{
		return _markerList.getElements();
	}
	
	/**
	 * Retreives video original size.
	 */
	public function getSize() : Dimension
	{
		return _size;
	}
	
	/**
	 * Defines video duration ( in ms );
	 */
	public function getDuration() : Number
	{
		return _duration; 	
	}
	
	/**
	 * Sets current video metadata.
	 */
	public function setMetaData( metaobject : VideoMetaData ) : Void
	{
		_duration = metaobject.duration;
		_size = new Dimension( metaobject.width, metaobject.height );
		_meta = metaobject;
	}
	
	/**
	 * Returns current video metadata.
	 */
	public function getMetaData() : VideoMetaData
	{
		return _meta;	
	}
	
	/**
	 * Returns {@code true} if video is streamed throw PHP streaming file.
	 */
	public function isPHPStreaming() : Boolean
	{
		return _phpStreaming;	
	}
	
	/**
	 * Returns a basic object structure with item properties.
	 * 
	 * <p>Used for SharedObject save process.
	 */
	public function toObject() : Object
	{
		return { url : _url, title : _title };	
	}
	
}